﻿/*----------------------------------------------------------------
//  <copyright file="YfxytSmsSigner.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2024-03-04 14:54</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.SMS.Signer
{
    #region "逸峰信盈通短信签名功能"
    /// <summary>
    /// 逸峰信盈通短信签名功能
    /// </summary>
    public class YfxytSmsSigner : ISmsSigner
    {
        #region 属性
        #region "获取 服务提供者对象"
        /// <summary>
        /// 获取 服务提供者对象
        /// </summary>
        protected IServiceProvider ServiceProvider { get; }
        #endregion
        #region "获取 事件总线"
        /// <summary>
        /// 获取 事件总线
        /// </summary>
        protected IEventBus EventBus => ServiceProvider.GetService<IEventBus>();
        #endregion
        #region "获取 日志对象"
        /// <summary>
        /// 获取 日志对象
        /// </summary>
        protected ILogger Logger { get; }
        #endregion
        #region "获取 短信配置选项"
        /// <summary>
        /// 获取 短信配置选项
        /// </summary>
        protected SmsOptions SmsOpt => ServiceProvider.GetService<IConfiguration>()?.GetSmsOptions();
        #endregion

        #endregion

        #region "构造函数"
        #region "初始化一个逸峰信盈通短信签名功能的新实例"
        /// <summary>
        /// 初始化一个逸峰信盈通短信签名功能的新实例 <see cref="YfxytSmsSigner"/> 的新实例
        /// </summary>
        /// <param name="provider">服务提供者</param>
        public YfxytSmsSigner(IServiceProvider provider)
        {
            ServiceProvider = provider;
            Logger = provider.GetLogger(GetType());
        }
        #endregion

        #endregion

        #region "方法"
        #region "申请短信签名"
        /// <summary>
        /// 申请短信签名
        /// </summary>
        /// <param name="paramsDto">短信签名参数DTO</param>
        /// <returns></returns>
        public virtual async Task<OperationResult<SignResponse>> AddAsync(SignParamsDto paramsDto)
        {
            var result = OperationResult.Unsupported<SignResponse>(I18N.T("逸峰信盈通短不支持申请短信签名"));
            //触发申请成功事件
            if (result.Succeeded)
            {
                SmsSignEventData eventData = new()
                {
                    ParamsDto = paramsDto,
                    Response = result.Data,
                };
                await EventBus?.PublishAsync(this, eventData);
            }
            return await Task.Factory.StartNew(() => result);
        }
        #endregion
        #region "删除短信签名"
        /// <summary>
        /// 删除短信签名
        /// </summary>
        /// <param name="signName">短信签名</param>
        /// <returns></returns>
        public virtual async Task<OperationResult<SignResponse>> DeleteAsync(string signName)
        {
            var result = OperationResult.Unsupported<SignResponse>(I18N.T("逸峰信盈通短不支持删除短信签名"));
            //触发删除成功事件
            if (result.Succeeded)
            {
                SmsSignEventData eventData = new()
                {
                    Response = result.Data,
                };
                await EventBus?.PublishAsync(this, eventData);
            }
            return await Task.Factory.StartNew(() => result);
        }
        #endregion
        #region "修改短信签名"
        /// <summary>
        /// 修改短信签名
        /// </summary>
        /// <param name="paramsDto">短信签名参数DTO</param>
        /// <returns></returns>
        public virtual async Task<OperationResult<SignResponse>> ModifyAsync(SignParamsDto paramsDto)
        {
            var result = OperationResult.Unsupported<SignResponse>(I18N.T("逸峰信盈通短不支持修改短信签名"));
            //触发修改成功事件
            if (result.Succeeded)
            {
                SmsSignEventData eventData = new()
                {
                    ParamsDto = paramsDto,
                    Response = result.Data,
                };
                await EventBus?.PublishAsync(this, eventData);
            }
            return await Task.Factory.StartNew(() => result);
        }
        #endregion
        #region "查询短信签名"
        /// <summary>
        /// 查询短信签名
        /// </summary>
        /// <param name="signName">短信签名</param>
        /// <returns></returns>
        public virtual async Task<OperationResult<SignDetailResponse>> QueryAsync(string signName)
        {
            var result = OperationResult.Unsupported<SignDetailResponse>(I18N.T("逸峰信盈通短不支持查询短信签名"));
            //触发查询成功事件
            if (result.Succeeded)
            {
                SmsSignDetailEventData eventData = new()
                {
                    Response = result.Data,
                };
                await EventBus?.PublishAsync(this, eventData);
            }
            return await Task.Factory.StartNew(() => result);
        }
        #endregion

        #endregion

        #region "私有方法"

        #endregion

    }
    #endregion

}
